Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema:[
      {
        label:'前景颜色值，包括按钮、标题、状态栏的颜色，仅支持 #ffffff 和 #000000',
        prop:'frontColor',
        type:'picker',
        labelOptions:['#ffffff', '#000000'], //选项
        valueOptions:['#ffffff', '#000000'], //选项对应的值
        value: ''
      },
      {
        label:'背景颜色值，有效值为十六进制颜色',
        prop:'backgroundColor',
        type:'text',
        value: ''
      },
      {
        label:'动画变化时间，单位 ms',
        prop:'duration',
        type:'number',
        value: 0
      },
      {
        label:'动画变化方式',
        prop:'timingFunc',
        type:'picker',
        labelOptions:['linear', 'easeIn', 'easeOut', 'easeInOut'], //选项
        valueOptions:['linear', 'easeIn', 'easeOut', 'easeInOut'], //选项对应的值
        value: 'linear'
      },
    ],
    formData:{
      frontColor: '#000000',
      backgroundColor: '#ff6600',
      duration: 0,
      timingFunc: 'linear'
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    apiName: ''
  },
  onLoad(options) {
    console.log('options', options)
    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
  },
  getFormData(e) {
    const formData = {}
    this.data.schema.forEach(item => {
      if(item.type === 'number') {
        if(!isNaN(+e.detail.formData[item.prop]) && e.detail.formData[item.prop] !== '') {
          formData[item.prop] = +e.detail.formData[item.prop]
        }
      } else {
        formData[item.prop] = e.detail.formData[item.prop]
      }
    })
    this.setData({
      formData: formData
    })
  },
  choose1(e) {
    const that = this;
    wx.setNavigationBarColor({
      frontColor: this.data.formData.frontColor,
      backgroundColor: this.data.formData.backgroundColor,
      animation: {
        duration: this.data.formData.duration,
        timingFunc: this.data.formData.timingFunc,
      },
      success(res) {
        that.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      },
      fail(err) {
        that.setData({
          result: err,
          apiName: e.currentTarget.dataset.apiname
        })
      }
    })
    
  }
})